<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 关键字搜索 -->
			<cl-search-key />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" name="demo-ships" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";

const { service } = useCool();

// cl-upsert
const Upsert = useUpsert({
	items: [
		// { prop: "shipId", label: "船的编号", required: true, component: { name: "el-input" } },
		// { prop: "teamId", label: "运动队编号", required: true, component: { name: "el-input" } },
		{ prop: "sn", label: "船系列号", required: true, component: { name: "el-input" } },
		{ prop: "shipName", label: "船名", required: true, component: { name: "el-input" } }
		// { prop: "description", label: "描述", required: true, component: { name: "el-input" } },
		// { prop: "online", label: "是否在线", required: true, component: { name: "el-input" } },
		// {
		// 	prop: "lastActivityStartTime",
		// 	label: "最后一次活动开始时间",
		// 	component: {
		// 		name: "el-date-picker",
		// 		props: { type: "datetime", valueFormat: "YYYY-MM-DD HH:mm:ss" }
		// 	}
		// },
		// {
		// 	prop: "lastActivityEndTime",
		// 	label: "最后一次活动结束时间",
		// 	component: {
		// 		name: "el-date-picker",
		// 		props: { type: "datetime", valueFormat: "YYYY-MM-DD HH:mm:ss" }
		// 	}
		// },
		// {
		// 	prop: "lastActivityStartLng",
		// 	label: "最后一次活动结开始经度",
		// 	required: true,
		// 	component: { name: "el-input" }
		// },
		// {
		// 	prop: "lastActivityStartLat",
		// 	label: "最后一次活动结开始纬度",
		// 	required: true,
		// 	component: { name: "el-input" }
		// },
		// {
		// 	prop: "lastActivityEndLng",
		// 	label: "最后一次活动结结束经度",
		// 	required: true,
		// 	component: { name: "el-input" }
		// },
		// {
		// 	prop: "lastActivityEndLat",
		// 	label: "最后一次活动结结束纬度",
		// 	required: true,
		// 	component: { name: "el-input" }
		// }
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		{ prop: "id", label: "ID" },
		// { prop: "shipId", label: "船的编号", width: 100 },
		// { prop: "teamId", label: "运动队编号", width: 100 },
		{ prop: "sn", label: "船系列号", width: 100 },
		{ prop: "shipName", label: "船名" },
		{ prop: "description", label: "描述" },
		{
			prop: "online",
			label: "是否在线",
			width: 100,
			formatter: (row: any, column: any, value: any, index: number) => {
				if (value == 1){
					return '在线'
				} else {
					return '离线'
				}
			}
		},
		// { prop: "lastActivityStartTime", label: "最后一次活动开始时间", width: 180 },
		// { prop: "lastActivityEndTime", label: "最后一次活动结束时间", width: 180 },
		// { prop: "lastActivityStartLng", label: "最后一次活动结开始经度", width: 180 },
		// { prop: "lastActivityStartLat", label: "最后一次活动结开始纬度", width: 180 },
		// { prop: "lastActivityEndLng", label: "最后一次活动结结束经度", width: 180 },
		// { prop: "lastActivityEndLat", label: "最后一次活动结结束纬度", width: 180 },
		// { prop: "createTime", label: "创建时间", sortable: "desc", width: 160 },
		// { prop: "updateTime", label: "更新时间", sortable: "custom", width: 160 },
		{ type: "op", buttons: ["edit", "delete"] }
	]
});

// cl-crud
const Crud = useCrud(
	{
		service: service.demo.ships
	},
	(app) => {
		app.refresh();
	}
);
</script>
